package com.lanp.native_test.ExecutorsRun.CustomTheadExecutor;

import org.apache.commons.lang3.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

public class PriorityBlockingQueueTest {
    /*
    基于数组、无边界、优先级执行
    最大任务容量是 最大线程数 + 队列最大长度
    不超过 阻塞队列数量，执行核心线程数量
    超过 阻塞队列数量，执行最大线程数量
     */
    static BlockingQueue blockingQueue = new PriorityBlockingQueue(10);


    private static final ThreadPoolExecutor TEST_EXECUTORS =
            new ThreadPoolExecutor(1, 4, 10, TimeUnit.MINUTES
                    , blockingQueue, Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 20; i++) {
            TestRunnable runnable = new TestRunnable(i);
            System.out.println("准备添加到队列" + i);
            TEST_EXECUTORS.execute(runnable);
        }

    }
}
